package com.neu.controller;


import com.github.pagehelper.PageInfo;
import com.neu.common.Result;
import com.neu.entity.Disease;
import com.neu.entity.Params;
import com.neu.entity.User;
import com.neu.mapper.UserMapper;
import com.neu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private UserMapper userMapper;

    @PostMapping
    public Result add(@RequestBody User user){
        if(user.getId() == null){
            userService.add(user);

        }else{
            userService.update(user);

        }
        //userService.add(user);
        return Result.success();
    }

    @GetMapping("/page")
    public Result page(Params params){
        PageInfo<User> info = userService.findBySearch(params);
        return Result.success(info);
    }

    @GetMapping("/selectAll")
    public Result selectAll(User user){
        List<User> list = userService.selectAll(user);
        return Result.success(list);

    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        userService.delete(id);
        return Result.success();
    }

    @DeleteMapping("/batch")
    public Result deleteBatch(@RequestParam List<Integer> ids){
        userService.deleteBatch(ids);
        return Result.success();
    }
}
